package com.bodu.core.entity.result;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.io.Serializable;

/**
 * 服务端返回数据
 *
 * @author gaoya
 */
@Getter
@ToString
@NoArgsConstructor
public class Result<T> implements Serializable {
    private Integer code;
    private String message;
    private T data;

    public static Result success() {
        return new Result(RStateEnum.SUCCESS.getCode(), RStateEnum.SUCCESS.getMessage());
    }

    public static Result success(String msg) {
        RStateEnum scsState = RStateEnum.SUCCESS;
        return new Result(RStateEnum.SUCCESS.getCode(), msg);
    }

    public static <T> Result success(T data) {
        RStateEnum scsState = RStateEnum.SUCCESS;
        return new Result(scsState.getCode(), scsState.getMessage(), data);
    }

    public static <T> Result success(String msg, T data) {
        return new Result(RStateEnum.SUCCESS.getCode(), msg, data);
    }

    public static <T> Result success(Integer code, String msg, T data) {
        return new Result(code, msg, data);
    }

    public static <T> Result<T> fail() {
        return new Result(RStateEnum.REQUEST_ERROR.getCode(), RStateEnum.REQUEST_ERROR.getMessage());
    }

    public static <T> Result fail(String msg) {
        return new Result(RStateEnum.REQUEST_ERROR.getCode(), msg);
    }

    public static <T> Result fail(Integer code, String msg) {
        return new Result(code, msg);
    }

    public Result(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public Result(Integer code, String message) {
        this.code = code;
        this.message = message;
    }
}
